/*
* Copyright 2016 YONYOU Corporation Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project         marketing

* @Package         com.yonyou.marketing.message.push.provider

* @Author          LuZhen

* @FileName        PushMessageHandleHistory

* @Date            2016/11/16

----------------------------------------------------------------------------------
*     Date          Who             Version         Comments
* 1. 2016/11/16        LuZhen          1.0             Create Source
*
----------------------------------------------------------------------------------
*/
package com.yonyou.gmmc.service.wechatpush.provider;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.PropertyFilter;

import javax.persistence.*;

import java.util.Calendar;
import java.util.Date;

@Entity
@Table(name="TT_PUSH_HISTORY")
@SequenceGenerator(name="SEQ_TT_PUSH_HISTORY",sequenceName="SEQ_TT_PUSH_HISTORY") 
public class PushMessageHandleHistory {


    private static PropertyFilter JSONFILTER;

    static {
        JSONFILTER = new PropertyFilter() {
            @Override
            public boolean apply(Object object, String name, Object value) {
                return !name.equalsIgnoreCase("handleInfo");
            }
        };
    }

    public PushMessageHandleHistory(ProviderMessage providerMessage, MessagePushResult result,String receiverId) {
        Calendar calnedar = Calendar.getInstance();
        calnedar.setTime(new Date());
        //最终推送结果
        this.isSuccess = result.getSuccess();
        this.message =result.getMessage();
        //处理信息
        this.operationDate = providerMessage.getOrigin().getOrigin().getHandleInfo().getLastHandleDate();
        this.operator = providerMessage.getOrigin().getOrigin().getHandleInfo().getLastHandler();
        this.pushId = providerMessage.getOrigin().getOrigin().getHandleInfo().getPushId();
        //消息内容持久化
        this.messageContent = JSON.toJSONString(providerMessage.getOrigin().getOrigin(),JSONFILTER);
        this.createDate = calnedar.getTime();
        this.receiverId = receiverId;
        this.sourceType = providerMessage.getOrigin().getOrigin().getMessage().getSourceType();
        this.dealerCode = providerMessage.getOrigin().getOrigin().getSender().getDealerCode();
        this.applicationId = providerMessage.getOrigin().getOrigin().getSender().getClientAppId();
    }

    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SEQ_TT_PUSH_HISTORY")
    private long id;

    public String getPushId() {
        return pushId;
    }

    public void setPushId(String pushId) {
        this.pushId = pushId;
    }

    @Column(nullable = false)
    private String pushId;

    @Column(nullable = false)
    private Boolean isSuccess;

    @Column(length = 1000)
    private String message;

    @Column(nullable = false ,length = 100)
    private String operator;

    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date operationDate;

    @Column(nullable = false)
    @Lob
    private String messageContent;
    
    @Column(nullable = false)
    private String receiverId;
    
    @Column(nullable = false)
    private Integer sourceType;
    
    @Column(nullable = true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;
    
    @Column(nullable = true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateDate;
    
    @Column(nullable = true)
    private Long createBy;
    
    @Column(nullable = true)
    private Long updateBy;
    
    @Column(nullable = true)
    private String dealerCode;
    
    @Column(nullable = true)
    private String applicationId;



    public long getId() {
        return id;
    }


    public String getOperator() {
        return operator;
    }

    public Date getOperationDate() {
        return operationDate;
    }

    public String getMessage() {
        return message;
    }

    public String getMessageContent() {
        return messageContent;
    }


    public void setId(long id) {
        this.id = id;
    }


    public void setMessage(String message) {
        this.message = message;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public void setOperationDate(Date operationDate) {
        this.operationDate = operationDate;
    }

    public void setMessageContent(String messageContent) {
        this.messageContent = messageContent;
    }

    
    /**
     * @return the isSuccess
     */
    public Boolean getIsSuccess() {
        return isSuccess;
    }

    
    /**
     * @param isSuccess the isSuccess to set
     */
    public void setIsSuccess(Boolean isSuccess) {
        this.isSuccess = isSuccess;
    }

    
    /**
     * @return the receiverId
     */
    public String getReceiverId() {
        return receiverId;
    }

    
    /**
     * @param receiverId the receiverId to set
     */
    public void setReceiverId(String receiverId) {
        this.receiverId = receiverId;
    }
    
    
    /**
     * @return the sourceType
     */
    public Integer getSourceType() {
        return sourceType;
    }

    
    /**
     * @param sourceType the sourceType to set
     */
    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }

    /**
     * @return the createDate
     */
    public Date getCreateDate() {
        return createDate;
    }

    
    /**
     * @param createDate the createDate to set
     */
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    
    /**
     * @return the updateDate
     */
    public Date getUpdateDate() {
        return updateDate;
    }

    
    /**
     * @param updateDate the updateDate to set
     */
    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    
    /**
     * @return the createBy
     */
    public Long getCreateBy() {
        return createBy;
    }

    
    /**
     * @param createBy the createBy to set
     */
    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    
    /**
     * @return the updateBy
     */
    public Long getUpdateBy() {
        return updateBy;
    }

    
    /**
     * @param updateBy the updateBy to set
     */
    public void setUpdateBy(Long updateBy) {
        this.updateBy = updateBy;
    }

    
    /**
     * @return the dealerCode
     */
    public String getDealerCode() {
        return dealerCode;
    }

    
    /**
     * @param dealerCode the dealerCode to set
     */
    public void setDealerCode(String dealerCode) {
        this.dealerCode = dealerCode;
    }

    
    /**
     * @return the applicationId
     */
    public String getApplicationId() {
        return applicationId;
    }

    
    /**
     * @param applicationId the applicationId to set
     */
    public void setApplicationId(String applicationId) {
        this.applicationId = applicationId;
    }

    
    
    
}
